/**
 * TB_DOOR_CURRENTPERMISSION
 * 
 *
 *<pre> 
 * 开发公司：苏州东大金点信息技术有限公司
 * 开发人员：唐红锋
 * 邮箱地址：55872655@qq.com
 * 创建时间：2019-10-22 16:49:55
 *</pre>
 */
$(function() {
	currentPermission  = new CurrentPermission();
	currentPermission.init();
	
	formUrl = currentPermission.formUrl;
});

(function() {
	//定义常量
	var 	_consts = {
			GRID : "#currentPermissionGrid",// 列表对象
			PAGER : "#currentPermissionPager",// 列表分页
			FORM : '#currentPermissionForm',// 表单form
			FORMGET : '#currentPermissionFormGet'// 表单form
			
	};
	/**
	 * TB_DOOR_CURRENTPERMISSION 对象
	 * @returns {CurrentPermission}
	 */
	CurrentPermission = function() {
		//定义属性
	};
	
var dtFormatter = function (cellValue, options, rowObject) {
		   if(cellValue==null||cellValue==""){
			   return "";
		   }
		   var date = new Date(cellValue);
		   　    y = date.getFullYear();
		   　　m = date.getMonth() + 1;
		  　     d = date.getDate();
		   h = date.getHours() ;
		   f  = date.getMinutes();
		   s  = date. getSeconds();
		    
		   if(m<10){
			   m= '0'+m;
		   }
		   if(d<10){
			   d= '0'+d;
		   }
		   if(h<10){
			   h= '0'+h;
		   }
		   if(f<10){
			   f= '0'+f;
		   }
		   if(s<10){
			   s= '0'+s;
		   }
		   　　return y+"-"+m+"-"+d+" "+h+":"+f+":"+s;

}
	/**
	 * 方法
	 */
	CurrentPermission.prototype = {
		consts:	_consts,
		/**
		 * 初始化
		 */
		init : function() {
			if (this.hasInit) // 是否已初始化
				return false;
			this.hasInit = true;
			if ($(this.consts.GRID).length > 0){//列表
				this._initGridList();
				
			}
			if ($(this.consts.FORM).length > 0){//表单
				this._initForm();
				this._initData();
				this._initOffice('e');
			}
			if ($(this.consts.FORMGET).length > 0){// 明细页面office控件初始化
				this._initOffice('r');
			}
		},
		_initOffice : function(_rights){
		},

		/**
		 * 初始列表
		 */
		_initGridList : function() {
			var me = this;
			$(this.consts.GRID).GridList(
					{
						url :  __ctx+'/rdp/CurrentPermission/currentPermission/listPidPage.htm',
						pager :this.consts.PAGER,
						colNames: ['ID','授权类型','学工号','卡UID','学生名称','控制器编号','控制器名称','门名称','下发状态','分配时间','下发时间','时间段','开始时间','结束时间','管理'],
				        colModel: [{
				                 	   name:'id',
				                	   index: 'ID'

										
				                	 	,hidden:true,key:true
				                	 	},  {
						                 	   name:'ext1',
						                	   index: 'EXT1',
						                	   formatter:function(cellValue){
						                		  
						                		   if(cellValue=='1'){
						                			   return "用户授权";
						                		   }else if(cellValue=='2') {
						                			   return "身份授权";				                			   
						                		   }else{
						                			   return "";	
						                		   }
						                	   } 
                                                                                }, {
				                 	   name:'studentno',
				                	   index: 'STUDENTNO'

										
				                	 					                	 	}, {
				                 	   name:'studentuid',
				                	   index: 'STUDENTUID'

										
																			    },    {
							     	   name:'username',
							           index: 'USERNAME'

																			    },{
				                 	   name:'controllerid',
				                	   index: 'CONTROLLERID'

										
																			   },{
								        name:'controllername',
										index: 'CONTROLLERNAME'

																					
																				},  {
					                    name:'controllerno',
										 index: 'CONTROLLERNO'

																		       },   {
				                 	   name:'permissionstatus',
														 index: 'PERMISSIONSTATUS',
														 formatter:function(cellValue){
				                		   if(cellValue=='0'){
				                			   return "分配中";
				                		   }
				                		   else if(cellValue=='1'){
				                			   return "已分配";
				                		   }else if(cellValue=='2') {
				                			   return "已取消";				                			   
				                		   }else{
				                			   return "";	
				                		   }
				                		   
				                	   }		

										
				                	 					                	 	}, {
				                 	   name:'allocatedtime',
				                	   index: 'ALLOCATEDTIME'
				                	 	,formatter: dtFormatter
										
				                	 					                	 	}, {
				                 	   name:'downtime',
				                	   index: 'DOWNTIME'
				                	 	,formatter: dtFormatter
										
				                	 					                	 	}, {
				                 	   name:'timeseg',
				                	   index: 'TIMESEG'

										
				                	 					                	 	},  {
				                 	   name:'starttime',
				                	   index: 'STARTTIME'
				                	 	,formatter:'timestamp'
										
				                	 					                	 	}, {
				                 	   name:'endtime',
				                	   index: 'ENDTIME'
				                	 	,formatter: 'timestamp'
										
				                	 					                	 	},  {
									name : '__manage',
									width : 30,
									sortable:false,
									classes:'rowOps',
									formatter : 'manage',
									formatoptions :[{
										label:'明细',
										classes:'btn btn-primary fa fa-detail',
										action: __ctx+'/rdp/CurrentPermission/currentPermission/get.htm?id={id}'
									}]
								} ]
	
					});
		},
		
		/**
		 * 初始化表单
		 */
		_initForm : function() {
			var me = this, form = $(this.consts.FORM), frm = form.form();
			me.formUrl = new com.lc.form.FormData(form);
			// 触发表单验证
			frm.valid();
			// 处理表单保存
			$(document).on('click', 'a.fa-save', function() {
				var $el = $(this);
				$el.button('loading');
				// office提交
        		OfficePlugin.submit();
				me.formUrl.submit(me._showResponse, $el);
			});
		},
		/**
		 * 初始化数据
		 */
		_initData : function(){
			if(!$.isEmpty(frameElement) 
				&& !$.isEmpty(frameElement.dialog) 
				&& !$.isEmpty(frameElement.dialog.params)
				&& !$.isEmpty(frameElement.dialog.params.data)){
				var data = frameElement.dialog.params.data;
				this.formUrl.setData("[name^='m:']", data);
				AttachementControl.initDataTo($("div[name='div_attachment_container']")); //附件初始化
			}else{
				$("[name^='m:']", $(_consts.FORM)).each(function(){
					var data = $(this);
	        		// 单选框特殊处理 
	            	if(data.is('input') && "radio" == data.attr("type")){
			        		var defaultVal = data.attr("defaultVal");
			        		var defaultValue = data.attr("defaultValue");
		            		if(defaultValue=="true"&&defaultVal=="true"){
		            			data.prop("checked", "checked");
		            		}
		        	}
		        });
			}
			
			this.formUrl.validate();
		},
		/**
		 * 表单成功返回信息
		 * 
		 * @param responseText
		 */
		_showResponse : function(responseText) {
			var msg = new com.lc.form.ResultMessage(responseText);
			if (msg.isSuccess()) {
				DialogUtil.confirm(msg.getMessage() + ',是否继续操作',
					function(rtn) {
					if(rtn)
						window.location.reload(true);
					else
						window.location.href = __ctx+'/rdp/CurrentPermission/currentPermission/list.htm';
					});
			} else {
				DialogUtil.error(msg.getMessage());
			}
		}
	};
})();